Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: watch public files that are imported by JavaScript #9770

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aleclarson
Copy link
Member

Description

Because of how resolveId in the assetPlugin returns the virtual ID as-is, it's hard for me to associate file changes with a ModuleNode (the module node is addressed by the virtual ID instead of the absolute file path). This means public files imported in SSR won't trigger a hot reload.

To fix this, I'm returning { id: publicFile, meta: { publicUrl: id } } from the resolveId hook in question. Unfortunately, returning meta from resolveId is not supported by Vite until #7477 or similar is merged, so this PR is blocked.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@@ -137,7 +137,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
// will fail to resolve in the main resolver. handle them here.
const publicFile = checkPublicFile(id, config)
if (publicFile) {
return id
return { id: publicFile, meta: { publicUrl: id } }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically, the full file path is returned as the resolved ID and the original module URL is cached in meta.publicUrl for the assetPlugin to use.

Copy link
Member

@bluwy bluwy Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call this.addWatchFile(publicFile) instead? Or maybe it's better to always return the absolute path, but I'm not sure any side effects with that.

@bluwy bluwy marked this pull request as draft April 1, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants